﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace FUSE
{
    public partial class ImageComponent : DrawableGameComponent
    {
        public enum DrawMode { Center = 1, Stretch, };
        // Texture to draw
        protected readonly Texture2D texture;
        // Draw mode
        protected readonly DrawMode drawMode;
        // SpriteBatch
        protected SpriteBatch spriteBatch = null;
        // Image rectangle
        protected Rectangle imageRect;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="game"> the Game object</param>
        /// <param name="texture"> Texture to draw</param>
        /// <param name="drawMode"> Draw mode *eye roll*</param>
        public ImageComponent(Game game, Texture2D texture, DrawMode drawMode)
            : base(game)
        {
            this.texture = texture;
            this.drawMode = drawMode;
            // Get the current sprite batch
            spriteBatch = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
            // Create a rectangle with the size and position of the image
            switch (drawMode)
            {
                case DrawMode.Center:
                    imageRect = new Rectangle((Game.Window.ClientBounds.Width - texture.Width) / 2, (Game.Window.ClientBounds.Height - texture.Height) / 2,
                        texture.Width, texture.Height);
                    break;

                case DrawMode.Stretch:
                    imageRect = new Rectangle(0, 0, Game.Window.ClientBounds.Width, Game.Window.ClientBounds.Height);
                    break;
            }
        }

        /// <summary>
        /// Allows the GameComponent to draw itself
        /// </summary>
        /// <param name="gameTime">Provides timing values</param>
        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Draw(texture, imageRect, Color.White);
            base.Draw(gameTime);
        }
    }
}
